package com.hamster.crm.web;

import com.hamster.crm.pojo.Opinionaire;
import com.hamster.crm.service.OpinionaireService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问卷调查的 Controller
 * @author Tarry
 * @create 2019/12/23 11:23
 */
@RestController
@RequestMapping("opinionaire")
public class OpinionaireController {
    @Autowired
    private OpinionaireService opinionaireService;

    /**
     * 添加问卷
     * @return 状态码200
     */
    @PostMapping("insert")
    public ResponseEntity<Void> insert(@RequestBody Opinionaire opinionaire){
        opinionaireService.insert(opinionaire);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据问卷id删除问卷
     * @param ids 问卷id集合
     * @return 状态码200
     */
    @PostMapping("delete")
    public ResponseEntity<Void> delete(@RequestBody List<String> ids){
        opinionaireService.delete(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 后台管理，下发问卷
     * @param ids 问卷id 集合
     * @return
     */
    @PostMapping("send")
    public ResponseEntity<Void> send(@RequestBody List<String> ids){
        opinionaireService.send(ids);
        return ResponseEntity.ok().build();
    }

    /**
     * 根据问卷id预览问卷
     * @param id 问卷 id
     * @return Opinionaire 问卷内容
     */
    @GetMapping("get")
    public ResponseEntity<Opinionaire> get(@RequestParam String id){
        Opinionaire opinionaire = opinionaireService.get(id);
        return ResponseEntity.ok(opinionaire);
    }

    /**
     * 问卷列表
     * @return List<Opinionaire>
     */
    @GetMapping("list")
    public ResponseEntity<List<Opinionaire>> list(){
        List<Opinionaire> opinionaireList = opinionaireService.list();
        return ResponseEntity.ok(opinionaireList);
    }

}
